package demo.core.runtime.impl;

import java.util.*;

import org.osgi.framework.Bundle;

import demo.core.runtime.extension.ExtendConfig;
import demo.core.runtime.extension.ExtendPoint;
import demo.core.runtime.extension.Extension;
import demo.core.runtime.extension.RemoveException;

public class ExtendConfigImpl implements ExtendConfig {
	private ExtendPoint extendPoint;
	private Set<Extension> extensions=new LinkedHashSet<Extension>();
	
	public ExtendConfigImpl(Bundle bundle,String extendPoint){
		this.extendPoint=new ExtendPoint(bundle,extendPoint);
	}
	
	@Override
	public ExtendPoint getExtendPoint() {
		return extendPoint;
	}
	
	@Override
	public Extension[] getExtensions() {
		return extensions.toArray(new Extension[0]);
	}
	@Override
	public Extension getExtension(Object extension) {
		for(Extension extensionObj:extensions){
			if(extensionObj.getExtension()==extension)
				return extensionObj;
		}
		return null;
	}
	
	void addExtension(Extension extension){
		extensions.add(extension);
	}
	void removeExtension(Extension extension) throws RemoveException{
		extensions.remove(extension);
	}
}
